<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="68px">
      <el-form-item label="公司标识" prop="vehicleIdId">
        <el-input
          v-model="queryParams.vehicleIdId"
          placeholder="请输入公司标识"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="车辆厂牌" prop="brand">
        <el-input
          v-model="queryParams.brand"
          placeholder="请输入车辆厂牌"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="车辆所有人" prop="owner">
        <el-input
          v-model="queryParams.owner"
          placeholder="请输入车辆所有人"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="车辆颜色" prop="color">
        <el-input
          v-model="queryParams.color"
          placeholder="请输入车辆颜色"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="发动机号/电动机号" prop="engineNumber">
        <el-input
          v-model="queryParams.engineNumber"
          placeholder="请输入发动机号/电动机号"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="车辆注册日期" prop="registrationDate">
        <el-date-picker clearable
          v-model="queryParams.registrationDate"
          type="date"
          value-format="yyyy-MM-dd"
          placeholder="请选择车辆注册日期">
        </el-date-picker>
      </el-form-item>
      <el-form-item label="发动机排量" prop="displacement">
        <el-input
          v-model="queryParams.displacement"
          placeholder="请输入发动机排量"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="车辆照片文件编号" prop="photoFileNumber">
        <el-input
          v-model="queryParams.photoFileNumber"
          placeholder="请输入车辆照片文件编号"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="运输证字号" prop="transportCertificateNumber">
        <el-input
          v-model="queryParams.transportCertificateNumber"
          placeholder="请输入运输证字号"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="车辆运输证发证机构" prop="transportCertificateIssuingAuthority">
        <el-input
          v-model="queryParams.transportCertificateIssuingAuthority"
          placeholder="请输入车辆运输证发证机构"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="车辆经营区域" prop="operatingArea">
        <el-input
          v-model="queryParams.operatingArea"
          placeholder="请输入车辆经营区域"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="车辆运输证有效期起" prop="transportCertificateValidFrom">
        <el-date-picker clearable
          v-model="queryParams.transportCertificateValidFrom"
          type="date"
          value-format="yyyy-MM-dd"
          placeholder="请选择车辆运输证有效期起">
        </el-date-picker>
      </el-form-item>
      <el-form-item label="车辆运输证有效期止" prop="transportCertificateValidTo">
        <el-date-picker clearable
          v-model="queryParams.transportCertificateValidTo"
          type="date"
          value-format="yyyy-MM-dd"
          placeholder="请选择车辆运输证有效期止">
        </el-date-picker>
      </el-form-item>
      <el-form-item label="车辆初次登记日期" prop="firstRegistrationDate">
        <el-date-picker clearable
          v-model="queryParams.firstRegistrationDate"
          type="date"
          value-format="yyyy-MM-dd"
          placeholder="请选择车辆初次登记日期">
        </el-date-picker>
      </el-form-item>
      <el-form-item label="车辆下次年检时间" prop="nextAnnualInspectionDate">
        <el-date-picker clearable
          v-model="queryParams.nextAnnualInspectionDate"
          type="date"
          value-format="yyyy-MM-dd"
          placeholder="请选择车辆下次年检时间">
        </el-date-picker>
      </el-form-item>
      <el-form-item label="发票打印设备序列号" prop="invoicePrinterSerialNumber">
        <el-input
          v-model="queryParams.invoicePrinterSerialNumber"
          placeholder="请输入发票打印设备序列号"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="卫星定位装置品牌" prop="gpsBrand">
        <el-input
          v-model="queryParams.gpsBrand"
          placeholder="请输入卫星定位装置品牌"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="卫星定位装胃型号" prop="gpsModel">
        <el-input
          v-model="queryParams.gpsModel"
          placeholder="请输入卫星定位装胃型号"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="卫星定位装置IMEI号" prop="gpsImei">
        <el-input
          v-model="queryParams.gpsImei"
          placeholder="请输入卫星定位装置IMEI号"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="卫星定位设备安装日期" prop="gpsInstallationDate">
        <el-date-picker clearable
          v-model="queryParams.gpsInstallationDate"
          type="date"
          value-format="yyyy-MM-dd"
          placeholder="请选择卫星定位设备安装日期">
        </el-date-picker>
      </el-form-item>
      <el-form-item label="报备日期" prop="reportDate">
        <el-date-picker clearable
          v-model="queryParams.reportDate"
          type="date"
          value-format="yyyy-MM-dd"
          placeholder="请选择报备日期">
        </el-date-picker>
      </el-form-item>
      <el-form-item label="服务类" prop="serviceClass">
        <el-input
          v-model="queryParams.serviceClass"
          placeholder="请输入服务类"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="创建人" prop="creatorId">
        <el-input
          v-model="queryParams.creatorId"
          placeholder="请输入创建人"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="修改人" prop="modifierId">
        <el-input
          v-model="queryParams.modifierId"
          placeholder="请输入修改人"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button
          type="primary"
          plain
          icon="el-icon-plus"
          size="mini"
          @click="handleAdd"
          v-hasPermi="['system:info:add']"
        >新增</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="success"
          plain
          icon="el-icon-edit"
          size="mini"
          :disabled="single"
          @click="handleUpdate"
          v-hasPermi="['system:info:edit']"
        >修改</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="danger"
          plain
          icon="el-icon-delete"
          size="mini"
          :disabled="multiple"
          @click="handleDelete"
          v-hasPermi="['system:info:remove']"
        >删除</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="warning"
          plain
          icon="el-icon-download"
          size="mini"
          @click="handleExport"
          v-hasPermi="['system:info:export']"
        >导出</el-button>
      </el-col>
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>

    <el-table v-loading="loading" :data="infoList" @selection-change="handleSelectionChange">
      <el-table-column type="selection" width="55" align="center" />
      <el-table-column label="${comment}" align="center" prop="id" />
      <el-table-column label="公司标识" align="center" prop="vehicleIdId" />
      <el-table-column label="车辆厂牌" align="center" prop="brand" />
      <el-table-column label="车辆类型" align="center" prop="type" />
      <el-table-column label="车辆所有人" align="center" prop="owner" />
      <el-table-column label="车辆颜色" align="center" prop="color" />
      <el-table-column label="发动机号/电动机号" align="center" prop="engineNumber" />
      <el-table-column label="车辆注册日期" align="center" prop="registrationDate" width="180">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.registrationDate, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>
      <el-table-column label="车辆燃料类型" align="center" prop="fuelType" />
      <el-table-column label="发动机排量" align="center" prop="displacement" />
      <el-table-column label="车辆照片文件编号" align="center" prop="photoFileNumber" />
      <el-table-column label="运输证字号" align="center" prop="transportCertificateNumber" />
      <el-table-column label="车辆运输证发证机构" align="center" prop="transportCertificateIssuingAuthority" />
      <el-table-column label="车辆经营区域" align="center" prop="operatingArea" />
      <el-table-column label="车辆运输证有效期起" align="center" prop="transportCertificateValidFrom" width="180">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.transportCertificateValidFrom, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>
      <el-table-column label="车辆运输证有效期止" align="center" prop="transportCertificateValidTo" width="180">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.transportCertificateValidTo, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>
      <el-table-column label="车辆初次登记日期" align="center" prop="firstRegistrationDate" width="180">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.firstRegistrationDate, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>
      <el-table-column label="车辆检修状态" align="center" prop="maintenanceStatus" />
      <el-table-column label="车辆下次年检时间" align="center" prop="nextAnnualInspectionDate" width="180">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.nextAnnualInspectionDate, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>
      <el-table-column label="车辆年审核状志" align="center" prop="annualInspectionStatus" />
      <el-table-column label="发票打印设备序列号" align="center" prop="invoicePrinterSerialNumber" />
      <el-table-column label="卫星定位装置品牌" align="center" prop="gpsBrand" />
      <el-table-column label="卫星定位装胃型号" align="center" prop="gpsModel" />
      <el-table-column label="卫星定位装置IMEI号" align="center" prop="gpsImei" />
      <el-table-column label="卫星定位设备安装日期" align="center" prop="gpsInstallationDate" width="180">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.gpsInstallationDate, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>
      <el-table-column label="报备日期" align="center" prop="reportDate" width="180">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.reportDate, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>
      <el-table-column label="服务类" align="center" prop="serviceClass" />
      <el-table-column label="创建人" align="center" prop="creatorId" />
      <el-table-column label="修改人" align="center" prop="modifierId" />
      <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
        <template slot-scope="scope">
          <el-button
            size="mini"
            type="text"
            icon="el-icon-edit"
            @click="handleUpdate(scope.row)"
            v-hasPermi="['system:info:edit']"
          >修改</el-button>
          <el-button
            size="mini"
            type="text"
            icon="el-icon-delete"
            @click="handleDelete(scope.row)"
            v-hasPermi="['system:info:remove']"
          >删除</el-button>
        </template>
      </el-table-column>
    </el-table>
    
    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />

    <!-- 添加或修改【请填写功能名称】对话框 -->
    <el-dialog :title="title" :visible.sync="open" width="500px" append-to-body>
      <el-form ref="form" :model="form" :rules="rules" label-width="80px">
        <el-form-item label="公司标识" prop="vehicleIdId">
          <el-input v-model="form.vehicleIdId" placeholder="请输入公司标识" />
        </el-form-item>
        <el-form-item label="车辆厂牌" prop="brand">
          <el-input v-model="form.brand" placeholder="请输入车辆厂牌" />
        </el-form-item>
        <el-form-item label="车辆所有人" prop="owner">
          <el-input v-model="form.owner" placeholder="请输入车辆所有人" />
        </el-form-item>
        <el-form-item label="车辆颜色" prop="color">
          <el-input v-model="form.color" placeholder="请输入车辆颜色" />
        </el-form-item>
        <el-form-item label="发动机号/电动机号" prop="engineNumber">
          <el-input v-model="form.engineNumber" placeholder="请输入发动机号/电动机号" />
        </el-form-item>
        <el-form-item label="车辆注册日期" prop="registrationDate">
          <el-date-picker clearable
            v-model="form.registrationDate"
            type="date"
            value-format="yyyy-MM-dd"
            placeholder="请选择车辆注册日期">
          </el-date-picker>
        </el-form-item>
        <el-form-item label="发动机排量" prop="displacement">
          <el-input v-model="form.displacement" placeholder="请输入发动机排量" />
        </el-form-item>
        <el-form-item label="车辆照片文件编号" prop="photoFileNumber">
          <el-input v-model="form.photoFileNumber" placeholder="请输入车辆照片文件编号" />
        </el-form-item>
        <el-form-item label="运输证字号" prop="transportCertificateNumber">
          <el-input v-model="form.transportCertificateNumber" placeholder="请输入运输证字号" />
        </el-form-item>
        <el-form-item label="车辆运输证发证机构" prop="transportCertificateIssuingAuthority">
          <el-input v-model="form.transportCertificateIssuingAuthority" placeholder="请输入车辆运输证发证机构" />
        </el-form-item>
        <el-form-item label="车辆经营区域" prop="operatingArea">
          <el-input v-model="form.operatingArea" placeholder="请输入车辆经营区域" />
        </el-form-item>
        <el-form-item label="车辆运输证有效期起" prop="transportCertificateValidFrom">
          <el-date-picker clearable
            v-model="form.transportCertificateValidFrom"
            type="date"
            value-format="yyyy-MM-dd"
            placeholder="请选择车辆运输证有效期起">
          </el-date-picker>
        </el-form-item>
        <el-form-item label="车辆运输证有效期止" prop="transportCertificateValidTo">
          <el-date-picker clearable
            v-model="form.transportCertificateValidTo"
            type="date"
            value-format="yyyy-MM-dd"
            placeholder="请选择车辆运输证有效期止">
          </el-date-picker>
        </el-form-item>
        <el-form-item label="车辆初次登记日期" prop="firstRegistrationDate">
          <el-date-picker clearable
            v-model="form.firstRegistrationDate"
            type="date"
            value-format="yyyy-MM-dd"
            placeholder="请选择车辆初次登记日期">
          </el-date-picker>
        </el-form-item>
        <el-form-item label="车辆下次年检时间" prop="nextAnnualInspectionDate">
          <el-date-picker clearable
            v-model="form.nextAnnualInspectionDate"
            type="date"
            value-format="yyyy-MM-dd"
            placeholder="请选择车辆下次年检时间">
          </el-date-picker>
        </el-form-item>
        <el-form-item label="发票打印设备序列号" prop="invoicePrinterSerialNumber">
          <el-input v-model="form.invoicePrinterSerialNumber" placeholder="请输入发票打印设备序列号" />
        </el-form-item>
        <el-form-item label="卫星定位装置品牌" prop="gpsBrand">
          <el-input v-model="form.gpsBrand" placeholder="请输入卫星定位装置品牌" />
        </el-form-item>
        <el-form-item label="卫星定位装胃型号" prop="gpsModel">
          <el-input v-model="form.gpsModel" placeholder="请输入卫星定位装胃型号" />
        </el-form-item>
        <el-form-item label="卫星定位装置IMEI号" prop="gpsImei">
          <el-input v-model="form.gpsImei" placeholder="请输入卫星定位装置IMEI号" />
        </el-form-item>
        <el-form-item label="卫星定位设备安装日期" prop="gpsInstallationDate">
          <el-date-picker clearable
            v-model="form.gpsInstallationDate"
            type="date"
            value-format="yyyy-MM-dd"
            placeholder="请选择卫星定位设备安装日期">
          </el-date-picker>
        </el-form-item>
        <el-form-item label="报备日期" prop="reportDate">
          <el-date-picker clearable
            v-model="form.reportDate"
            type="date"
            value-format="yyyy-MM-dd"
            placeholder="请选择报备日期">
          </el-date-picker>
        </el-form-item>
        <el-form-item label="服务类" prop="serviceClass">
          <el-input v-model="form.serviceClass" placeholder="请输入服务类" />
        </el-form-item>
        <el-form-item label="创建人" prop="creatorId">
          <el-input v-model="form.creatorId" placeholder="请输入创建人" />
        </el-form-item>
        <el-form-item label="修改人" prop="modifierId">
          <el-input v-model="form.modifierId" placeholder="请输入修改人" />
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import { listInfo, getInfo, delInfo, addInfo, updateInfo } from "@/api/system/info";

export default {
  name: "Info",
  data() {
    return {
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 【请填写功能名称】表格数据
      infoList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        vehicleIdId: null,
        brand: null,
        type: null,
        owner: null,
        color: null,
        engineNumber: null,
        registrationDate: null,
        fuelType: null,
        displacement: null,
        photoFileNumber: null,
        transportCertificateNumber: null,
        transportCertificateIssuingAuthority: null,
        operatingArea: null,
        transportCertificateValidFrom: null,
        transportCertificateValidTo: null,
        firstRegistrationDate: null,
        maintenanceStatus: null,
        nextAnnualInspectionDate: null,
        annualInspectionStatus: null,
        invoicePrinterSerialNumber: null,
        gpsBrand: null,
        gpsModel: null,
        gpsImei: null,
        gpsInstallationDate: null,
        reportDate: null,
        serviceClass: null,
        creatorId: null,
        modifierId: null,
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {
        createTime: [
          { required: true, message: "创建时间不能为空", trigger: "blur" }
        ],
        updateTime: [
          { required: true, message: "修改时间不能为空", trigger: "blur" }
        ]
      }
    };
  },
  created() {
    this.getList();
  },
  methods: {
    /** 查询【请填写功能名称】列表 */
    getList() {
      this.loading = true;
      listInfo(this.queryParams).then(response => {
        this.infoList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        id: null,
        vehicleIdId: null,
        brand: null,
        type: null,
        owner: null,
        color: null,
        engineNumber: null,
        registrationDate: null,
        fuelType: null,
        displacement: null,
        photoFileNumber: null,
        transportCertificateNumber: null,
        transportCertificateIssuingAuthority: null,
        operatingArea: null,
        transportCertificateValidFrom: null,
        transportCertificateValidTo: null,
        firstRegistrationDate: null,
        maintenanceStatus: null,
        nextAnnualInspectionDate: null,
        annualInspectionStatus: null,
        invoicePrinterSerialNumber: null,
        gpsBrand: null,
        gpsModel: null,
        gpsImei: null,
        gpsInstallationDate: null,
        reportDate: null,
        serviceClass: null,
        creatorId: null,
        createTime: null,
        modifierId: null,
        updateTime: null
      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.id)
      this.single = selection.length!==1
      this.multiple = !selection.length
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset();
      this.open = true;
      this.title = "添加【请填写功能名称】";
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.reset();
      const id = row.id || this.ids
      getInfo(id).then(response => {
        this.form = response.data;
        this.open = true;
        this.title = "修改【请填写功能名称】";
      });
    },
    /** 提交按钮 */
    submitForm() {
      this.$refs["form"].validate(valid => {
        if (valid) {
          if (this.form.id != null) {
            updateInfo(this.form).then(response => {
              this.$modal.msgSuccess("修改成功");
              this.open = false;
              this.getList();
            });
          } else {
            addInfo(this.form).then(response => {
              this.$modal.msgSuccess("新增成功");
              this.open = false;
              this.getList();
            });
          }
        }
      });
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const ids = row.id || this.ids;
      this.$modal.confirm('是否确认删除【请填写功能名称】编号为"' + ids + '"的数据项？').then(function() {
        return delInfo(ids);
      }).then(() => {
        this.getList();
        this.$modal.msgSuccess("删除成功");
      }).catch(() => {});
    },
    /** 导出按钮操作 */
    handleExport() {
      this.download('system/info/export', {
        ...this.queryParams
      }, `info_${new Date().getTime()}.xlsx`)
    }
  }
};
</script>
